package inicio;


import java.awt.Color;
import java.awt.Font;
import java.awt.TextArea;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.table.DefaultTableModel;



import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.border.TitledBorder;
import manterAluguel.PainelCadastrarAluguel;
import manterAluguel.PainelPesquisarAluguel;
import materItens.PainelCadastrarItem;
import materItens.PainelPesquisarItem;






public class TelaGeral extends JFrame implements MouseListener{
	
	private JLabel cabecalho,guiaItens,guiaAluguel,guiItensCadastro,guiItensPesquisa;
	private ImageIcon IconCabecalho;
	private JMenuBar barraMenus;
	private JMenu menuArquivo, menuCadastro, menuAlugueis;
	private JMenuItem menuItenArquivoSair, menuItenCadasIten, menuItenCadasTemas, menuItenCadasUsuario, menuItenCadasSubgrupo, menuItemAluguelEditar, menuItemAluguelCadastrar, menuItemAluguelPesquisar, menuItemAluguelExcluir;
	private Font fonteGeral;
	private JButton bCadastrar, bPesquisar;
	private ImageIcon iconGuiaAlugel;
	
	private JDesktopPane panel = null;
	
	//Objetos de panel cadastrar
	private JPanel panelInicio;
	private JButton cadastrar = new JButton("OK");
	private JTable table;
	private JButton btVoltar;
	
	public TelaGeral(){
		
		setTitle("Kids Party");
		this.fonteGeral=new Font("comic sans", Font.PLAIN, 16);
		CarregarMenu();

		

		

		IconCabecalho = new ImageIcon(getClass().getResource("/imagens/cabecalho.png"));
		cabecalho = new JLabel(IconCabecalho);
		add(cabecalho).setBounds(-5,-5, IconCabecalho.getIconWidth(), IconCabecalho.getIconHeight());
	
		
		cadastrar.addMouseListener(this);
		
		guiaItens = new JLabel(new ImageIcon(getClass().getResource("/imagens/guiaItens.png")));
		add(guiaItens).setBounds(610, 168, 185, 85);
		
		iconGuiaAlugel = new ImageIcon(getClass().getResource("/imagens/guiaAlugueis.png"));
		guiaAluguel = new JLabel(iconGuiaAlugel);
		add(guiaAluguel).setBounds(610, 168, 185, 85);
		guiaAluguel.setVisible(false);
		
		guiItensCadastro = new JLabel(new ImageIcon(getClass().getResource("/imagens/guiaItensCadastrando.png")));
		add(guiItensCadastro).setBounds(400, 168, 267, 55);
		guiItensCadastro.setVisible(false);
		
		guiItensPesquisa = new JLabel(new ImageIcon(getClass().getResource("/imagens/guiaItensPesquisando.png")));
		add(guiItensPesquisa).setBounds(400, 168, 267, 55);
		guiItensPesquisa.setVisible(false);
		
		barraMenus=new JMenuBar();
		setBackground(Color.yellow);
		add(barraMenus).setBounds(0, 140, 800, 30);
		
		panelInicio = new JPanel();
		add(panelInicio).setBounds(0, 170, 800, 365);
		panelInicio.setLayout(null);
		
		
		
		bCadastrar = new JButton(new ImageIcon(getClass().getResource("/imagens/botaoCadastrar0.png")));
		panelInicio.add(bCadastrar).setBounds(10, 150, 369, 133);
		bCadastrar.setBorder(null);
		bCadastrar.setContentAreaFilled(false);
		bCadastrar.addMouseListener(this);
		
		bPesquisar = new JButton(new ImageIcon(getClass().getResource("/imagens/botaoPesquisar0.png")));
		panelInicio.add(bPesquisar).setBounds(420, 150, 369, 133);
		bPesquisar.setBorder(null);
		bPesquisar.setContentAreaFilled(false);
		bPesquisar.addMouseListener(this);
		
		

		btVoltar = new JButton("Voltar");
		add(btVoltar).setBounds(670, 540, 120, 30);
		btVoltar.setVisible(false);
		
		setSize(800,600);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setResizable(false);
		setLocationRelativeTo(null);
		setLayout(null);
		setVisible(true);
		
		
		
            bCadastrar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				btVoltar.setVisible(true);
				guiItensCadastro.setVisible(true);
				guiItensPesquisa.setVisible(false);
				
				menuItemAluguelCadastrar.setEnabled(false);
				menuItemAluguelPesquisar.setEnabled(false);
				menuItemAluguelEditar.setEnabled(false);
				menuItemAluguelExcluir.setEnabled(false);
				
				panel = new PainelCadastrarItem();
				panel.setBounds(5, 250, 785, 290);
				TelaGeral.this.add(panel);
				TelaGeral.this.remove(panelInicio);
				TelaGeral.this.repaint();
				
				System.out.println("Entrou no evento");
			
			}
		});
            
            bPesquisar.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				
    				btVoltar.setVisible(true);
    				guiItensCadastro.setVisible(false);
    				guiItensPesquisa.setVisible(true);
    				
    				menuItemAluguelCadastrar.setEnabled(false);
    				menuItemAluguelPesquisar.setEnabled(false);
    				menuItemAluguelEditar.setEnabled(false);
    				menuItemAluguelExcluir.setEnabled(false);
    				
    				panel = new PainelPesquisarItem();
    				panel.setBounds(5, 250, 785, 290);
    				TelaGeral.this.add(panel);
    				TelaGeral.this.remove(panelInicio);
    				TelaGeral.this.repaint();
    				
    				System.out.println("Entrou no evento");

    				
    			}
    		});
		
            btVoltar.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				System.out.println("Voltou");
    				
    				guiaAluguel.setVisible(false);
    				guiaItens.setVisible(true);
    				menuItemAluguelCadastrar.setEnabled(true);
    				menuItemAluguelPesquisar.setEnabled(true);
    				menuItemAluguelEditar.setEnabled(true);
    				menuItemAluguelExcluir.setEnabled(true);
    				
    				
    				
    				btVoltar.setVisible(false);
    				TelaGeral.this.panel.setVisible(false);
    				TelaGeral.this.remove(panel);
    				TelaGeral.this.add(panelInicio);
    				guiItensCadastro.setVisible(false);
    				guiItensPesquisa.setVisible(false);
    			}
    		});
	}
	

	private void CarregarMenu(){
		
		barraMenus=new JMenuBar();
		setBackground(Color.yellow);
		add(barraMenus).setBounds(0, 140, 800, 30);
		
		menuArquivo=new JMenu("Arquivo");
		menuArquivo.setFont(fonteGeral);
		barraMenus.add(menuArquivo);
		
		menuItenArquivoSair=new JMenuItem("Sair");
		menuItenArquivoSair.setFont(fonteGeral);
		menuItenArquivoSair.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
			}
		});
		menuArquivo.add(menuItenArquivoSair);
		
		menuCadastro=new JMenu("Cadastro");
		menuCadastro.setFont(fonteGeral);
		barraMenus.add(menuCadastro);
		
		menuItenCadasIten=new JMenuItem("Itens");
		menuItenCadasIten.setFont(fonteGeral);
//		menuItenCadasPosto.addActionListener(new tratadora());
		this.menuCadastro.add(menuItenCadasIten);
		
		menuItenCadasTemas=new JMenuItem("Temas");
		menuItenCadasTemas.setFont(fonteGeral);
//		menuItenCadasFornecedor.addActionListener(new tratadora());
		menuCadastro.add(menuItenCadasTemas);
		
		
		//Menu Alugueis (manter alugueis)
		menuAlugueis=new JMenu("Alugueis");
		menuAlugueis.setFont(fonteGeral);
		barraMenus.add(menuAlugueis);
		
		menuItemAluguelCadastrar=new JMenuItem("Cadastrar");
		menuItemAluguelCadastrar.setFont(fonteGeral);
		menuItemAluguelCadastrar.addActionListener(new tratadora());
		this.menuAlugueis.add(menuItemAluguelCadastrar);
		
		menuItemAluguelPesquisar=new JMenuItem("Pesquisar");
		menuItemAluguelPesquisar.setFont(fonteGeral);
		menuItemAluguelPesquisar.addActionListener(new tratadora());
		this.menuAlugueis.add(menuItemAluguelPesquisar);
		
		menuItemAluguelEditar=new JMenuItem("Editar");
		menuItemAluguelEditar.setFont(fonteGeral);
//		menuItemAluguelEditar.addActionListener(new tratadora());
		this.menuAlugueis.add(menuItemAluguelEditar);
		
		menuItemAluguelExcluir=new JMenuItem("Excluir");
		menuItemAluguelExcluir.setFont(fonteGeral);
//		menuItemAluguelExcluir.addActionListener(new tratadora());
		this.menuAlugueis.add(menuItemAluguelExcluir);
		
	}
	
	
	//Classe interna para tratamento dos eventos do Menu
	private class tratadora implements ActionListener, KeyListener{
		public void actionPerformed(ActionEvent e) {		
			
			if (e.getSource()==menuItemAluguelCadastrar){ 

				guiaAluguel.setVisible(true);
				guiaItens.setVisible(false);
				btVoltar.setVisible(true);
				guiItensCadastro.setVisible(true);
				guiItensPesquisa.setVisible(false);
				

				menuItemAluguelCadastrar.setEnabled(false);
				menuItemAluguelPesquisar.setEnabled(false);
				menuItemAluguelEditar.setEnabled(false);
				menuItemAluguelExcluir.setEnabled(false);
				
				
				panel = new PainelCadastrarAluguel();
				panel.setBounds(5, 250, 785, 290);
				TelaGeral.this.add(panel);
				TelaGeral.this.remove(panelInicio);
				TelaGeral.this.repaint();
			
			}
			
			if (e.getSource()==menuItemAluguelPesquisar){ 
	
				guiaAluguel.setVisible(true);
				guiaItens.setVisible(false);
				btVoltar.setVisible(true);
				guiItensCadastro.setVisible(false);
				guiItensPesquisa.setVisible(true);
				
				menuItemAluguelCadastrar.setEnabled(false);
				menuItemAluguelPesquisar.setEnabled(false);
				menuItemAluguelEditar.setEnabled(false);
				menuItemAluguelExcluir.setEnabled(false);
				
				panel = new PainelPesquisarAluguel();
				panel.setBounds(5, 250, 785, 290);
				TelaGeral.this.add(panel);
				TelaGeral.this.remove(panelInicio);
				TelaGeral.this.repaint();
			
			}
				
			}

		public void keyPressed(KeyEvent arg0) {}
		public void keyReleased(KeyEvent arg0) {}
		public void keyTyped(KeyEvent arg0) {}
			
		}
	
	public static void main(String[] args) {
		new TelaGeral();
	}


	@Override
	public void mouseClicked(MouseEvent e) {
	}


	@Override
	public void mouseEntered(MouseEvent e) {
		if(e.getSource() == bCadastrar){
			bCadastrar.setIcon(new ImageIcon(getClass().getResource("/imagens/botaoCadastrar1.png")));
		}

		if(e.getSource() == bPesquisar){
			bPesquisar.setIcon(new ImageIcon(getClass().getResource("/imagens/botaoPesquisar1.png")));
		}
		
	}
	@Override
	public void mouseExited(MouseEvent e) {
		if(e.getSource() == bCadastrar){
			bCadastrar.setIcon(new ImageIcon(getClass().getResource("/imagens/botaoCadastrar0.png")));
		}
		if(e.getSource() == bPesquisar){
			bPesquisar.setIcon(new ImageIcon(getClass().getResource("/imagens/botaoPesquisar0.png")));
		}
	}
	
	public void mousePressed(MouseEvent e) {}
	public void mouseReleased(MouseEvent e) {}
	
	public void setPanel(JDesktopPane panel) {
		this.panel = panel;
	}
	
}
